//=============================================================================
// tfConstructor.
//=============================================================================
class tfConstructor extends TFWeapon
	placeable;

var int myteam;

////////////CheckSentinel
simulated function baseSentinel SentinelInRange(float Range, bool bOnlyOwn, optional bool bAny)
{

    local Vector HitLocation, HitNormal;
	local Actor A;
	local Vector X, Y, Z;
//    local sentinelplayerreplicationinfo spri;

	GetViewAxes(X, Y, Z);

	foreach TraceActors(class'Actor', A, HitLocation, HitNormal, Instigator.Location + X * Range, Instigator.Location)
	{
		if(A == None)
			continue;

		if(A.bWorldGeometry)
			return None;

		if(A.IsA('baseSentinel'))
		{
		  //if(spri.Team.TeamIndex==Instigator.PlayerReplicationInfo.Team.TeamIndex)
		  //{
			//if(Sentinel(A).InstigatorController == instigator.Controller)
			//	return Sentinel(A);

			if(baseSentinel(A).PlayerReplicationInfo.team.TeamIndex == instigator.PlayerReplicationInfo.Team.TeamIndex)
				return baseSentinel(A);

			if(bAny)
				return baseSentinel(A);
   	      //}
		}
	}

	return None;
}
/////////Check Sentinel

/////////Check Station

simulated function tfstation StationInRange(float Range, bool bOnlyOwn, optional bool bAny)
{

    local Vector HitLocation, HitNormal;
	local Actor A;
	local Vector X, Y, Z;
//    local sentinelplayerreplicationinfo spri;

	GetViewAxes(X, Y, Z);

	foreach TraceActors(class'Actor', A, HitLocation, HitNormal, Instigator.Location + X * Range, Instigator.Location)
	{
		if(A == None)
			continue;

		if(A.bWorldGeometry)
			return None;

		if(A.IsA('tfstation'))
		{
		  //if(spri.Team.TeamIndex==Instigator.PlayerReplicationInfo.Team.TeamIndex)
		  //{
			//if(Sentinel(A).InstigatorController == instigator.Controller)
			//	return Sentinel(A);

			if(tfstation(A).MyTeam == instigator.PlayerReplicationInfo.Team.TeamIndex)
				return tfstation(A);

			if(bAny)
				return tfstation(A);
   	      //}
		}
	}

	return None;
}

/////////Check Station

/////////RECYCLE SENTINEL
simulated function DoRemove(BaseSentinel SentinelToRemove, controller killer)
{
//local Sentinel sent;
	if(SentinelToRemove == None)
		return;
    SentinelToRemove.SetRecycleState();
	SentinelToRemove.Died(killer, none, SentinelToRemove.Location);
}
////////RECYCLE SENTINEL

function bool ConsumeAmmo(int mode, float load, optional bool bAmountNeededIsMax)
{
	return true;
}

function Tick(float dt)
{
    if(pawn(owner)!=none && pawn(owner).playerreplicationinfo!=none)
    {
        AmmoCharge[0]=tfpri(pawn(owner).playerreplicationinfo).res;
        //MaxAmmo[0]=AmmoCharge[0];
    }
}

simulated function OutOfAmmo()
{
}

function bool CheckDist(int bm, vector loc)
{
    local tfStation s, b;
    local float dist;

    if(bm!=4 && bm!=5 && bm!=3) return true;

    dist=999999;

    foreach DynamicActors(class'taskforces.tfstation',s)
    {
        if(bm==4 && tfgenerator(s)!=none && vsize(s.location-loc)<dist)
        {
            b=s;
            dist=vsize(s.location-loc);
        }
        else if(bm==5 && (tfoutpost(s)!=none || tfbasecore(s)!=none) && vsize(s.location-loc)<dist)
        {
            b=s;
            dist=vsize(s.location-loc);
        }
        else if(bm==3 && tfarmory(s)!=none && vsize(s.location-loc)<dist)
        {
            b=s;
            dist=vsize(s.location-loc);
        }
    }

    if(bm==4 && dist>=500) return true;
    else if(bm==3 && dist>=500) return true;
    else if(bm==5 && dist>=tfgame(level.Game).OutpostDist*48) return true;

    if(bm==4 || bm==3) Playercontroller(instigator.controller).ReceiveLocalizedMessage(class'TaskForces.tfBuildFailMsg',505-dist,,,b);
    else Playercontroller(instigator.controller).ReceiveLocalizedMessage(class'TaskForces.tfBuildFailMsg',(tfgame(level.Game).OutpostDist*48+5)-dist,,,b);

    return false;
}

function bool CheckControl(int costs, int team, gamereplicationinfo gri)
{
    if(costs==600) return true;

    if(gri!=none && tfgri(gri).control[team]+costs<=tfgri(gri).maxcontrol[team])
        return true;

    Instigator.PlaySound(sound'TFMedia.tfGUIFail',SLOT_None,TransientSoundVolume);
    Playercontroller(instigator.controller).ReceiveLocalizedMessage(class'TaskForces.TFControlFailMsg');
    return false;
}

function bool CheckArea(int bm, vector loc)
{
    local tfStation st, s;
    local float dist;

if(bm==5 || !tfgame(level.Game).BuildAreas) return true;

		foreach DynamicActors(class'taskforces.tfstation',st)
		{
        if((st.myteam == instigator.PlayerReplicationInfo.Team.teamindex && (tfBasecore(st)!=None || (tfOutpost(st)!=None && tfOutpost(st).grade>0)) && (s==none || vsize(st.location-loc)<vsize(s.location-loc))))
            s=st;
		}
    dist=(float(tfgame(level.Game).outpostdist)*48)-vsize(s.location-loc);

    if(dist>=0) return true;
    else Playercontroller(instigator.controller).ReceiveLocalizedMessage(class'TaskForces.tfAreaFailMsg',dist/-48,,,s);

    return false;
}

function bool CheckTerr(int bm, vector loc)
{
    local tfStation st, s;
    local float dist;

if(bm==5 || !tfgame(level.Game).Terr) return true;

		foreach DynamicActors(class'taskforces.tfstation',st)
		{
        if((st.myteam != instigator.PlayerReplicationInfo.Team.teamindex && (tfBasecore(st)!=None || (tfOutpost(st)!=None && tfOutpost(st).grade>0)) && (s==none || vsize(st.location-loc)<vsize(s.location-loc))))
            s=st;
		}
    dist=(float(tfgame(level.Game).outpostdist)*48)-vsize(s.location-loc);

    if(dist>=0)
    {
    Playercontroller(instigator.controller).ReceiveLocalizedMessage(class'TaskForces.TFTerrFailMsg',dist/48,,,s);
     return false;
    }
    else
    {
    return true;
    }
}

defaultproperties
{
     FireModeClass(0)=Class'taskforces.TFConSpawnFire'
     FireModeClass(1)=Class'taskforces.TFConDummyFire'
     SelectAnim="Pickup"
     PutDownAnim="PutDown"
     IdleAnimRate=0.250000
     SelectSound=Sound'TFMedia.Misc.tfConSlct'
     SelectForce="Translocator_change"
     AIRating=-1.000000
     CurrentRating=-1.000000
     bCanThrow=False
     bDoAmmoRegen=False
     EffectOffset=(X=100.000000,Y=30.000000,Z=-19.000000)
     DisplayFOV=70.000000
     Priority=1
     HudColor=(B=222,G=222,R=222)
     GroupOffset=1
     PlayerViewOffset=(X=7.000000,Y=7.000000,Z=-4.500000)
     PlayerViewPivot=(Pitch=1000,Yaw=400)
     BobDamping=1.800000
     AttachmentClass=Class'taskforces.TFConAttach'
     IconMaterial=texture'HUDContent.Generic.HUD'
     IconCoords=(X2=2,Y2=2)
     ItemName="Multitool"
     mesh=SkeletalMesh'Weapons.TransLauncher_1st'
     Skins(0)=texture'TFMedia.Construction.tfConSkin'
     UV2Texture=Shader'XGameShaders.WeaponShaders.WeaponEnvShader'
     SkillCost=0
}
